package main

import (
	"context"
	"distributed/log"
	"distributed/registry"
	"distributed/service"
	"fmt"
	stdlog "log"
)

func main() {
	log.New("./distributed.log")
	host, port := "localhost", "4000"
	serviceURL := fmt.Sprintf("http://%s:%s", host, port)

	reg := registry.Registration{
		ServiceName:      registry.LogService,
		ServiceURL:       serviceURL,
		RequiredServices: make([]registry.ServiceName, 0),
		ServiceUpdateURL: serviceURL + "/services",
		HeartbeatURL:     serviceURL + "/heartbeat",
	}

	ctx, err := service.Start(
		context.Background(),
		reg,
		host,
		port,
		log.RegisterHandlers,
	)
	if err != nil {
		stdlog.Fatalln(err)
	}

	<-ctx.Done()
	fmt.Println("Shutting down log service")
}
